package drds.global_transaction.resource_manager.proxy.resource_manager;

import drds.global_transaction.resource_manager.execute.ExecuteTemplate;
import drds.global_transaction.resource_manager.execute.StatementExecuteTemplate;
import drds.global_transaction.resource_manager.proxy.datasource.AbstractConnectionProxy;
import drds.global_transaction.resource_manager.proxy.datasource.AbstractStatementProxy;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class StatementProxy<T extends Statement> extends AbstractStatementProxy<T>
{

	public StatementProxy(AbstractConnectionProxy abstractConnectionProxy, T statement) throws SQLException
	{
		this(abstractConnectionProxy, statement, null);
	}

	public StatementProxy(AbstractConnectionProxy abstractConnectionProxy, T statement, String sql) throws SQLException
	{
		super(abstractConnectionProxy, statement, sql);
	}

	@Override
	public boolean execute(String sql) throws SQLException
	{
		// TODO
		return false;
	}

	@Override
	public boolean execute(String sql, int autoGeneratedKeys) throws SQLException
	{
		// TODO
		return false;
	}

	@Override
	public boolean execute(String sql, int[] columnIndexes) throws SQLException
	{
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean execute(String sql, String[] columnNames) throws SQLException
	{
		throw new UnsupportedOperationException();
	}

	@Override
	public ResultSet executeQuery(String sql) throws SQLException
	{
		this.sql = sql;
		return ExecuteTemplate.execute(this, new StatementExecuteTemplate<ResultSet, T>()
		{
			@Override
			public ResultSet execute(Statement statement, Object... args) throws SQLException
			{
				return statement.executeQuery((String) args[0]);
			}
		}, sql);
	}

	@Override
	public int executeUpdate(String sql) throws SQLException
	{
		this.sql = sql;
		return ExecuteTemplate.execute(this, new StatementExecuteTemplate<Integer, T>()
		{
			@Override
			public Integer execute(Statement statement, Object... args) throws SQLException
			{
				return statement.executeUpdate((String) args[0]);
			}
		}, sql);
	}

	@Override
	public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException
	{
		// TODO
		return 0;
	}

	@Override
	public int executeUpdate(String sql, int[] columnIndexes) throws SQLException
	{
		throw new UnsupportedOperationException();
	}

	@Override
	public int executeUpdate(String sql, String[] columnNames) throws SQLException
	{
		throw new UnsupportedOperationException();
	}

	@Override
	public ConnectionProxy getConnectionProxy()
	{
		return (ConnectionProxy) super.getConnectionProxy();
	}
}
